package com.codingman.jpademo3;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;

public class Demo3 {
	public static void main(String[] args) {
		EntityManagerFactory emf = Persistence.createEntityManagerFactory("employee_unit");
		EntityManager em = emf.createEntityManager();

		em.getTransaction().begin();
		
		Department dep = new Department(1, "HR");
		em.persist(dep);
		
		Employee3 d1 = new Employee3(101, "Ann", 100.00);
		d1.setDepartment(dep);
		
		Employee3 d2 = new Employee3(102, "Bob", 200.00);
		d2.setDepartment(dep);
				
		em.persist(d1);
		em.persist(d2);

		em.getTransaction().commit();

		em.close();
		emf.close();
	}
}
